package com.javasm.service.impl;

import com.javasm.dao.GodCommunityDao;
import com.javasm.entity.GodCommunity;
import com.javasm.service.GodCommunityService;
import com.javasm.utils.MyBatisHeapler;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class GodCommunityServiceImpl implements GodCommunityService {
    @Override
    public List<GodCommunity> listCommunitys(GodCommunity inputCommunity, Integer page, Integer pageSize) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        GodCommunityDao mapper = sqlSession.getMapper(GodCommunityDao.class);
        List<GodCommunity> godCommunities = mapper.listCommunitys(inputCommunity, (page - 1) * pageSize, pageSize);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return godCommunities;
    }
    public int countCommunitys(GodCommunity inputCommunity) {

        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        GodCommunityDao mapper = sqlSession.getMapper(GodCommunityDao.class);
        int count = mapper.countCommunitys(inputCommunity);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return count;

    }

    public int addGodCommunity(GodCommunity inputCommunity) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        GodCommunityDao mapper = sqlSession.getMapper(GodCommunityDao.class);
        Integer resNum = mapper.addGodCommunity(inputCommunity);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }



    public int deleteGodCommunityById(Integer communityId) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        GodCommunityDao mapper = sqlSession.getMapper(GodCommunityDao.class);
        Integer resNum = mapper.deleteGodCommunityById(communityId);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }

    public int editGodCommunity(GodCommunity inputCommunity) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        GodCommunityDao mapper = sqlSession.getMapper(GodCommunityDao.class);
        Integer resNum = mapper.editGodCommunity(inputCommunity);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }

    public GodCommunity getGodCommunityById(Integer communityId) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        GodCommunityDao mapper = sqlSession.getMapper(GodCommunityDao.class);
        GodCommunity community = mapper.getGodCommunityById(communityId);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return community;
    }
}
